using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using FlexminAPI;

namespace FlexminAdmin.Forms
{
	internal partial class ChangePasswordForm : Form
	{
		private IHost computer;

		public ChangePasswordForm(IHost comp, string newPassword)
		{
			InitializeComponent();
			computer = comp;
			newPasswordBox.Text = newPassword;
		}

		private void cancelButton_Click(object sender, EventArgs e)
		{
			Close();
		}

		private void okButton_Click(object sender, EventArgs e)
		{
			computer.Password = newPasswordBox.Text;
			Close();
		}

		private void CheckEquality()
		{
			if (newPasswordBox.Text.Length == 0)
			{
				newPasswordBox.BackColor = Color.Pink;
				confirmPasswordBox.BackColor = Color.White;
				okButton.Enabled = false;
				return;
			}

			if (newPasswordBox.Text.Equals(confirmPasswordBox.Text))
			{
					newPasswordBox.BackColor = Color.White;
					confirmPasswordBox.BackColor = Color.White;
					okButton.Enabled = true;
			}
			else
			{
				newPasswordBox.BackColor = Color.White;
				confirmPasswordBox.BackColor = Color.Pink;
				okButton.Enabled = false;
			}
		}

		private void newPasswordBox_TextChanged(object sender, EventArgs e)
		{
			CheckEquality();
		}

		private void confirmPasswordBox_TextChanged(object sender, EventArgs e)
		{
			CheckEquality();
		}

		private void confirmPasswordBox_KeyPress(object sender, KeyPressEventArgs e)
		{
			if (e.KeyChar == '\r')
			{
				if (okButton.Enabled)
					okButton.PerformClick();
			}
		}
	}
}